import $ from '../../utils/ajax.js';
import util from '../../utils/util.js';
const app = getApp();
Page({
    data: {
        tabs: 0,
        content: []
    },
    onLoad(options) {
        this.onPost();
    },
    applyTabs({ target: { dataset: { index } } }) {
        this.setData({
            tabs: Number(index),
            content: [],
        }, () => {
            this.onPost();
        })
    },
    onAuditing(e){
        wx.navigateTo({
            url: '/pages/auditing/auditing?second=100&item=' + JSON.stringify(e.currentTarget.dataset.item)
        })
    },
    onPost() {
        $.p(app.wxApp.url + 'agentNew/getRoleList', {
            type: this.data.tabs
        }, app.onStrart, (res) => {
            this.setData({
                content: res.data
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
    onAgent(){
        wx.navigateTo({
            url: '/pages/login/agent/agent?second=100'
        })
    },
    onSwitchRole(e) {
        $.p(app.wxApp.url + 'agentNew/switchRole', {
            roleId: e.target.dataset.id
        }, app.onStrart, (res) => {
            wx.setStorage({
                key: 'xfjtk',
                data: res.data.ticket,
                success: () => {
                    wx.navigateBack({
                        delta: 1,
                    })
                }
            })
        }, (res) => {
            util.showToast(res.data)
        })
    }
})